<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>签到补录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{../../lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{../../css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
            <label class="layui-form-label required">打卡日期</label>
            <div class="layui-input-inline">
                <input type="text" id="startDate" name="startDate" autocomplete="off" class="layui-input date">
            </div>
    </div>
    <div class="layui-form-item">
            <label class="layui-form-label required">上班时间</label>
            <div class="layui-input-inline">
                <input type="text" id="starttime" name="start" autocomplete="off" class="layui-input date">
            </div>
    </div>
    <div class="layui-form-item">
            <label class="layui-form-label required">下班时间</label>
            <div class="layui-input-inline">
                <input type="text" id="endtime" name="end" autocomplete="off" class="layui-input date">
            </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">员工</label>
        <div class="layui-input-block" style="width: 190px">
            <select name="employee_name" lay-verify="required">
                <option value="">请选择</option>
                <option th:each="emp:${empList}" th:value="${emp.name}">
                    <span th:text="${emp.name}"></span>
                </option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">考勤状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="正常" checked="">
            <input type="radio" name="status" value="0" title="异常">
        </div>
    </div>


<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">考勤添加</button>
    </div>
</div>
</div>
<script th:src="@{../../lib/layui/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.$;

        laydate.render({
            elem: '#startDate',
            type: 'date'
            //指定元素
        });
        laydate.render({
            elem: '#starttime',
            type: 'datetime'
            //指定元素
        });
        laydate.render({
            elem: '#endtime',
            type: 'datetime'
            //指定元素
        });


        form.on('submit(saveBtn)', function (data) {
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            $("#btn-submit").attr("disabled", "disabled").addClass("layui-btn-disabled");
            //提交数据
            var url = "/attendance/add";
            $.post(url, data.field, function (res) {
                console.log(res);
                if (res.code === 0) {
                    //成功提示
                    layer.msg(res.message, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        //关闭窗口,刷新数据表格
                        parent.refreshTable();
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                } else {
                    $("#btn-submit").removeAttr("disabled", "disabled").removeClass("layui-btn-disabled");
                    //失败则提示错误消息,窗口不关闭
                    layer.msg('新增部门失败,请联系管理员', {
                        icon: 2,
                        time: 2000, //2秒关闭（如果不配置，默认是3秒）
                        anim: 6
                    }, function () {
                        //do something
                    });
                }
            })
            //关掉窗口并刷新
            //失败则提示错误信息
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</body>
</html>
